<template>
	<view class="container">
		<view class="promotion_entrance" v-if="id==1">
			<image :style="{width:quanyizhongxin_w,height:quanyizhongxin_h}"  :src="'https://zhangjie.jdmuguzhid.com/uploads/社区驿站版.jpg'"></image>
		</view>
		<view class="promotion_entrance" v-else-if="id==2">
			<image :style="{width:quanyizhongxin_w,height:quanyizhongxin_h}"  :src="'https://zhangjie.jdmuguzhid.com/uploads/区县驿站.jpg'"></image>
		</view>
		<view class="promotion_entrance" v-else-if="id==4">
			<image :style="{width:quanyizhongxin_w,height:quanyizhongxin_h}"  :src="'https://zhangjie.jdmuguzhid.com/uploads/区县驿站.jpg'"></image>
		</view>
		<view class="promotion_entrance" v-else="id==3">
			<image :style="{width:quanyizhongxin_w,height:quanyizhongxin_h}"  :src="'https://zhangjie.jdmuguzhid.com/uploads/市级驿站版.jpg'"></image>
		</view>
		<view :style="{width:lijigoumai_w,height:lijigoumai_h}" class="lijigoumai" v-on:click="zhifuxuanxiang(id)"></view>
		<view class="dialog" :style="{width:width}" v-show="display==1">
			<view class="dialog_foot">

				<view class='yuebuzu' data-type="group" v-show="yuebuzu==1">余额不足 <text class="yue">¥ {{balance}}</text></view>
				<view class='yuezhifu' data-type="group" v-on:click="zhifu(id,1)" v-show="yuebuzu==0">余额支付 <text class="yue">¥ {{balance}}</text></view>
				<view class='weixinzhifu' data-type="group" v-on:click="zhifu(id,2)">微信支付</view>
			</view>
		</view>
		<view class="mask" :style="{width:width,height:h}" v-show="display==1" v-on:click="dialog_close"></view>

<!--		<view class="alert_"></view>-->
<!--		<view class="mask" :style="{width:width,height:h}" v-show="display==2" v-on:click="dialog_close"></view>-->
	</view>
</template>
<style>
	page{background: #F4F4F4;}
	.yue{
		font-size: 12px;margin-left: 4px}
	.mask{position: fixed;bottom: 0;left:0;opacity: 0.5;background: #000000;z-index: 99999;}
	.dialog{z-index:999999;background: #FFFFFF;position: fixed;bottom:0;left:0;max-height: 800upx;overflow-y: auto;
		display:flex;flex-direction: column;justify-content: flex-end;align-items: flex-start;padding-top:20upx;}
	.dialog_pic image{width: 100%;}
	.specs_unit image{width:60upx;margin-right:20upx;}
	.dialog_foot{width:96%;margin:10upx 2%;display: flex;justify-content: flex-end;align-items: center;height: 100upx;}
	.goods_property image{width:50upx;height: 50upx;}
	.title_price text{text-decoration: line-through;color: #CCCCCC;font-size:40upx;padding-left:20upx;}
	.share image{width:45upx;height: 45upx;}
	.service image{width:100%;}
	.shop_name image{width: 50%;}
	.shop_info_view image{width:100%;}
	.weixinzhifu{background:#ff1844;width: 57%;margin-left: 2%;text-align: center;height: 80upx;line-height:80upx;font-size: 38upx;
		color: white;border-radius: 40upx 40upx 40upx 40upx;}
	.yuezhifu{background:#ff1844;width: 57%;margin-right: 2%;text-align: center;height: 80upx;line-height:80upx;font-size: 38upx;
		color: white;border-radius: 40upx 40upx 40upx 40upx;}
	.yuebuzu{background:#c1c1c1;width: 57%;margin-right: 2%;text-align: center;height: 80upx;line-height:80upx;font-size: 38upx;
		color: white;border-radius: 40upx 40upx 40upx 40upx;}
	.jian image{width:30upx;height: 30upx;}
	.list_unit image{width:50upx;height: 50upx;}
	.lijigoumai{
		margin-top: -20%;
		margin-left: 5%;
		position: absolute;
	}
	.mask{position: fixed;bottom: 0;left:0;opacity: 0.5;background: #000000;z-index: 99999;}
	.dialog{z-index:999999;background: #FFFFFF;position: fixed;bottom:0;left:0;max-height: 800upx;overflow-y: auto;display:flex;flex-direction: column;justify-content: flex-end;align-items: flex-start;padding-top:20upx;}
	/*.alert_ {*/
	/*	border: red solid 1px;*/
	/*	width: 70%;*/
	/*	height: 30%;*/
	/*	position: absolute;*/
	/*	top: 25%;*/
	/*	left: 15%;*/
	/*	z-index: 999999;*/
	/*}*/
	/*.mask{position: fixed;bottom: 0;left:0;opacity: 0.5;background: #000000;z-index: 99999;}*/

</style>
<script>
	//#ifdef H5
	import wxjs   from '../../jweixin/lib/index.js';
	//#endif
	export default {
		data() {
			return {
				quanyizhongxin_w:'40px',
				quanyizhongxin_h:'40px',
				lijigoumai_w:'40px',
				lijigoumai_h:'40px',
				zhifuanniu_w:'40px',
				zhifuanniu_h:'40px',
				h:'40px',
				height:'40px',
				width:'40px',
				display:0,
				balance:0,
				yuebuzu:0,
				url: getApp().globalData.url,
				id:1
			}
		},
		onLoad(e) {
			var res = uni.getSystemInfoSync();
			var w = res.windowWidth;
			this.quanyizhongxin_w = w+'px';
			this.quanyizhongxin_h = w*1.48+'px';
			this.lijigoumai_w = w*0.9+'px';
			this.lijigoumai_h = w/10+'px';
			this.zhifuanniu_w = w*0.425+'px';
			this.zhifuanniu_h = w/20+'px';
			this.h = res.windowHeight+"px";
			this.height = w*4/4+"px";
			this.width  = w+"px";
			this.balance = uni.getStorageSync("balance");

			let curPage = getCurrentPages();
			let params = curPage[curPage.length - 1].options; //获取当前页面参数，如果有则返回参数的对象，没有参数返回空对象{}
			this.id = params.id;
		},
		onShow(){

		},
		methods: {
			zhifuxuanxiang:function(id)
			{
				uni.showModal({
					title: '提示',
					// 提示文字
					content: '请携带"邀请码"联系微信号"18525061788"的客服进行购买',
					// 取消按钮的文字自定义
					cancelText: "取消",
					// 确认按钮的文字自定义
					confirmText: "复制",
					//删除字体的颜色
					confirmColor:'red',
					//取消字体的颜色
					cancelColor:'#000000',
					success: function(res) {
						if (res.confirm) {
							uni.setClipboardData({data:'18525061788'});
							uni.showToast({
								title:"复制成功",
								duration:1000
							})
							// 执行确认后的操作
						}
						// else {
						// 	// 执行取消后的操作
						// }
					}
				})
				// var member_id = uni.getStorageSync("member_id");
				// console.log(member_id)
				// if(member_id=="")
				// {
				// 	uni.showModal({
				// 		title:"操作提示",
				// 		content:"请先登录在进行购买",
				// 		showCancel:false,
				// 		success: (res) => {
				// 			uni.switchTab({
				// 				url:"../member/index"
				// 			})
				// 		}
				// 	})
				// }
				// else
				// {
				// 	if (id==1)
				// 	{
				// 		if (this.balance < 10000)
				// 		{
				// 			this.yuebuzu = 1;
				// 		}
				// 	}
				// 	if (id==2)
				// 	{
				// 		if (this.balance < 50000)
				// 		{
				// 			this.yuebuzu = 1;
				// 		}
				// 	}
				// 	if (id==3)
				// 	{
				// 		if (this.balance < 200000)
				// 		{
				// 			this.yuebuzu = 1;
				// 		}
				// 	}
				// 	this.balance = uni.getStorageSync("balance");
				// 	this.display = 1;
				// }
			},
			dialog_close:function()
			{
				this.display = 0;
			},
			zhifu:function(id,type)
			{
				var that = this;
				console.log(this.url);

				console.log(id)
				console.log(type)

				if (id == 1)
				{
					var money = 10000;
				}
				else if (id == 2)
				{
					var money = 50000;
				}
				else
				{
					var money = 200000;
				}

				var member_id = uni.getStorageSync("member_id");
				if (type == 1)
				{
					uni.showModal({
						title: "支付提示",
						content: "确认余额支付"+money+"元?",
						success: function success(res) {
							if (res.confirm)
							{
								uni.request({
									url: that.url+'/wechat_order_pay',
									data: {member_id:member_id,type:type,money:money},
									header: {'Content-Type': 'application/json'},
									success: (res) => {
										if (res.data.status === 0)
										{
											uni.showModal({
												title:"操作提示",
												content:"出错啦",
												showCancel:false
											})
										}
									}
								});
							}
						}
					});
				}
				else
				{
					uni.showModal({
						title: "支付提示",
						content: "确认微信支付"+money+"元?",
						success: function success(res) {
							if (res.confirm)
							{
								uni.request({
									url: that.url+'/wechat_order_pay',
									data: {member_id:member_id,type:type,money:money},
									header: {'Content-Type': 'application/json'},
									success: (res) => {
										if (res.data.status === 0)
										{
											uni.showModal({
												title:"操作提示",
												content:"出错啦",
												showCancel:false
											})
										}
										else
										{
											that.wechat_pay(id, res.data.result.appId,
													res.data.result.nonceStr,
													res.data.result.package,
													res.data.result.paySign,
													res.data.result.signType,
													res.data.result.timeStamp);
										}
									}
								});
							}
						}
					});
				}
			},
			wechat_pay: function wechat_pay(id, appId, nonceStr, Package, paySign, signType, timeStamp)
			{
				var that = this;
				uni.requestPayment({
					provider: 'wxpay',
					timeStamp: timeStamp,
					nonceStr: nonceStr,
					package: Package,
					signType: 'MD5',
					paySign: paySign,
					success: function success(res) {
						console.log('success:' + JSON.stringify(res));
						if (res.errMsg == "requestPayment:ok")
						{
							that.update_order_status(id);
						}
					},
					fail: function fail(err) {
						// console.log('fail:' + JSON.stringify(err));
					},
					complete: function complete()
					{
						that.submit_status = 1;
					} });

			},
			initialize:function()
			{

			}
		}
	}

</script>

